import { defineStore } from 'pinia'
import { getRouterListApi } from '@/api/router'
import router from '@/router/index'
import { formatRouter, flatRouterList } from '@/modules/dynamicRotuer'
import { RouteRecordRaw } from 'vue-router'
export const useRouteStore = defineStore('routeStore', {
  state: () => ({
    routes: [], // 原始的路由数据
    flatRoutes: [], // 扁平化路由之后的数据
  }),
  actions: {
    async setRoutes() {
      let res: any = await getRouterListApi()
      if (res.status == 0) {
        this.routes = res.data
        this.flatRoutes = flatRouterList(res.data)
        await formatRouter(router, this.routes)
      }
    },
  },
})
